import subprocess
import os
import sys
from pathlib import Path


def exec(cmd: list[str], env: dict[str, str] = {}):
    process = subprocess.Popen(
        cmd,
        cwd=Path(__file__).parent.parent,
        # stdout=subprocess.PIPE,
        # stderr=subprocess.STDOUT,
        # text=True,
        # bufsize=1,
        # universal_newlines=True,
        env={**os.environ.copy(), **env},
    )
    # all_outputs = ""
    # Capture and print output in real-time
    # while True:
    #     output = process.stdout.readline()
    #     if output == "" and process.poll() is not None:
    #         break
    #     if output:
    #         print(output.strip(), flush=True)
    #         all_outputs += output
    # Get the return code after the process completes
    # return_code = process.wait()
    # if return_code != 0:
    #     # Also capture stderr in case of error
    #     _, stderr = process.communicate()
    #     raise subprocess.CalledProcessError(return_code, cmd, stderr=stderr)

    # return all_outputs
    return ""
